home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / medowl.zip / MDIFILE / MDIFILE.CPP next >
C/C++ Source or Header  |  1994-08-15  |  7KB  |  223 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991,1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\applicat.h>
  6. #include <owl\medtfile.h>
  7. #include <owl\mdi.h>
  8. #include <owl\decmdifr.h>
  9. #include <owl\statusba.h>
  10. #include <owl\controlb.h>
  11. #include <owl\buttonga.h>
  12. #include <owl\gdiobjec.h>
  13. #include "mdifile.h"
  14. #include <owl\editfile.rh>
  15.  
  16. const char AppName[] = "MDI File Editor";
  17.  
  18. const TDecoratedFrame::TLocation Location[] = {
  19.   TDecoratedFrame::Top,
  20.   TDecoratedFrame::Left,
  21.   TDecoratedFrame::Right
  22. };
  23.  
  24. class TEditFileKB : public TMagmaEditFile{
  25.   public:
  26.     TEditFileKB(TWindow*        parent = 0,
  27.                 int             id = 0,
  28.                 const char far* text = 0,
  29.                 int x = 0, int y = 0, int w = 0, int h = 0,
  30.                 const char far* fileName = 0,
  31.                 TModule*        module = 0)
  32.     : TMagmaEditFile(parent, id, text, x, y, w, h, fileName, module) {}
  33.   DECLARE_RESPONSE_TABLE(TEditFileKB);
  34. };
  35. DEFINE_RESPONSE_TABLE1(TEditFileKB, TMagmaEditFile)
  36. END_RESPONSE_TABLE;
  37.  
  38. //----------------------------------------------------------------------------
  39.  
  40. class TMDIFileApp : public TApplication {
  41.   public:
  42.     TMDIFileApp(const char* name) : TApplication(name) {}
  43.     void InitMainWindow();
  44.  
  45.   protected:
  46.     TOpenSaveDialog::TData   FileData;
  47.     TMDIClient*              Client;
  48.     TGadgetWindow::THintMode HintMode;
  49.     TDecoratedFrame*         Frame;
  50.     TControlBar*             ControlBar;
  51.     int                      ControlBarLoc;
  52.     
  53.   protected:
  54.     void CmFileNew();
  55.     void CmFileOpen();
  56.     void CmToggleHint();
  57.     void CeToggleHint(TCommandEnabler&);
  58.     void CmToggleBar();
  59.     
  60.   DECLARE_RESPONSE_TABLE(TMDIFileApp);
  61.  
  62. };
  63.  
  64. DEFINE_RESPONSE_TABLE1(TMDIFileApp, TApplication)
  65.   EV_COMMAND(CM_FILENEW, CmFileNew),
  66.   EV_COMMAND(CM_FILEOPEN, CmFileOpen),
  67.   EV_COMMAND(CM_TOGGLEHINT, CmToggleHint),
  68.   EV_COMMAND_ENABLE(CM_TOGGLEHINT, CeToggleHint),
  69.   EV_COMMAND(CM_TOGGLEBAR, CmToggleBar),
  70. END_RESPONSE_TABLE;
  71.  
  72.  
  73. static TControlBar*
  74. BuildControlBar(TWindow* parent, TControlBar::TTileDirection direction)
  75. {
  76.   TControlBar* cb = new TControlBar(parent, direction);
  77.   cb->Insert(*new TButtonGadget(CM_FILENEW, CM_FILENEW));
  78.   cb->Insert(*new TButtonGadget(CM_FILEOPEN, CM_FILEOPEN));
  79.   cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE));
  80.   cb->Insert(*new TButtonGadget(CM_FILESAVEAS, CM_FILESAVEAS));
  81.  
  82.   cb->Insert(*new TSeparatorGadget(6));
  83.   cb->Insert(*new TButtonGadget(CM_EDITUNDO, CM_EDITUNDO));
  84.   cb->Insert(*new TButtonGadget(CM_EDITCUT, CM_EDITCUT));
  85.   cb->Insert(*new TButtonGadget(CM_EDITCOPY, CM_EDITCOPY));
  86.   cb->Insert(*new TButtonGadget(CM_EDITPASTE, CM_EDITPASTE));
  87.  
  88.   cb->Insert(*new TSeparatorGadget(6));
  89.   cb->Insert(*new TButtonGadget(CM_EDITFIND, CM_EDITFIND));
  90.   cb->Insert(*new TButtonGadget(CM_EDITREPLACE, CM_EDITREPLACE));
  91.   cb->Insert(*new TButtonGadget(CM_EDITFINDNEXT, CM_EDITFINDNEXT));
  92.  
  93.   cb->Insert(*new TSeparatorGadget(6));
  94.   cb->Insert(*new TButtonGadget(CM_TOGGLEHINT, CM_TOGGLEHINT,
  95.                                 TButtonGadget::NonExclusive));
  96.   cb->Insert(*new TSeparatorGadget(6));
  97.   cb->Insert(*new TButtonGadget(CM_TOGGLEBAR, CM_TOGGLEBAR));
  98.  
  99.   cb->Attr.Style |= WS_CLIPSIBLINGS;    // since toolbar may move around
  100.   cb->Attr.Id = IDW_TOOLBAR;            // From MDIFILE.H, so we can hide it
  101.  
  102.   return cb;
  103. }
  104.  
  105. //
  106. // Construct the TMDIFileApp's MainWindow of class TMDIFileWindow,
  107. // loading its menu, accelerator table & icon
  108. //
  109. void
  110. TMDIFileApp::InitMainWindow()
  111. {
  112.   Client = new TMDIClient;
  113.   Frame = new TDecoratedMDIFrame(Name, IDM_EDITFILE_DOC, *Client, TRUE);
  114.   MainWindow = Frame;
  115.  
  116.   Frame->Attr.AccelTable = IDA_MDIFILE;
  117.   Frame->SetMenuDescr(TMenuDescr(IDM_EDITFILE_DOC, 1, 0, 0, 1, 1, 0));
  118.   Frame->SetIcon(this, IDI_MULTIFILE);
  119.  
  120.   //
  121.   // Construct, build and insert a control bar into the frame. Start out at
  122.   // the top of the frame
  123.   //
  124.   HintMode = TGadgetWindow::PressHints;
  125.   ControlBar = BuildControlBar(Frame, TControlBar::Horizontal);
  126.   ControlBarLoc = 0;
  127.   Frame->Insert(*ControlBar, Location[ControlBarLoc]);
  128.  
  129.   // Construct a status bar & insert it at the bottom
  130.   //
  131.   TStatusBar* sb = new TStatusBar(0, TGadget::Recessed,
  132.            TStatusBar::CapsLock | TStatusBar::NumLock | TStatusBar::Overtype);
  133.  
  134.   Frame->Insert(*sb, TDecoratedFrame::Bottom);
  135.   
  136.   EnableCtl3d(TRUE);
  137.  
  138.   // Initialize the file data struct used for open and saveas
  139.   //
  140.   FileData.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
  141.   FileData.SetFilter(string(*this, IDS_FILEFILTER).c_str());
  142. }
  143.  
  144. //
  145. // Respond to "New" command by constructing, creating, and setting up a
  146. // new TFileWindow MDI child
  147. //
  148. void
  149. TMDIFileApp::CmFileNew()
  150. {
  151.   TMDIChild* child = new TMDIChild(*Client, "", new TMagmaEditFile(0, 0, 0));
  152.   child->SetMenuDescr(TMenuDescr(IDM_EDITFILE_CHILD, 0, 2, 0, 0, 0, 0));
  153.   child->SetIcon(this, IDI_DOC);
  154.  
  155.   TMDIChild* curChild = Client->GetActiveMDIChild();
  156.   if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
  157.     child->Attr.Style |= WS_MAXIMIZE;
  158.  
  159.   child->Create();
  160. }
  161.  
  162. //
  163. // Respond to "Open" command by constructing, creating, and setting up a
  164. // new TFileWindow MDI child
  165. //
  166. void
  167. TMDIFileApp::CmFileOpen()
  168. {
  169.   *FileData.FileName = 0;
  170.   if (TFileOpenDialog(MainWindow, FileData).Execute() == IDOK) {
  171.     TMDIChild* child = new TMDIChild(*Client, "", new TMagmaEditFile(0, 0, 0, 0, 0, 0, 0, FileData.FileName));
  172.     child->SetMenuDescr(TMenuDescr(IDM_EDITFILE_CHILD, 0, 2, 0, 0, 0, 0));
  173.     child->SetIcon(this, IDI_DOC);
  174.  
  175.     TMDIChild* curChild = Client->GetActiveMDIChild();
  176.     if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
  177.       child->Attr.Style |= WS_MAXIMIZE;
  178.  
  179.     child->Create();
  180.   }
  181. }
  182.  
  183. void
  184. DoCreateChild(TWindow* win, void*)
  185. {
  186.   if (win->IsFlagSet(wfAutoCreate))
  187.     win->Create();
  188. }
  189.  
  190. void
  191. TMDIFileApp::CeToggleHint(TCommandEnabler& ce)
  192. {
  193.   ce.SetCheck(HintMode == TGadgetWindow::EnterHints);
  194. }
  195.  
  196. void
  197. TMDIFileApp::CmToggleHint()
  198. {
  199.   HintMode = HintMode==TGadgetWindow::PressHints ?
  200.                TGadgetWindow::EnterHints :
  201.                TGadgetWindow::PressHints;
  202.  
  203.   ControlBar->SetHintMode(HintMode);
  204.   ControlBar->SetHintCommand(-1);  // make sure we don't leave hint text dangling
  205. }
  206.  
  207. void
  208. TMDIFileApp::CmToggleBar()
  209. {
  210.   ControlBarLoc = (ControlBarLoc+1) % COUNTOF(Location);
  211.   ControlBar->SetDirection(ControlBarLoc==0 ?
  212.                            TControlBar::Horizontal : TControlBar::Vertical);
  213.   Frame->Insert(*ControlBar, Location[ControlBarLoc]);
  214.   Frame->Layout();
  215. }
  216.  
  217. int
  218. OwlMain(int /*argc*/, char* /*argv*/ [])
  219. {
  220.   return TMDIFileApp(AppName).Run();
  221. }
  222.  
  223.